package com.qianfeng.smartplatform.controller;

//
//                            _ooOoo_  
//                           o8888888o  
//                           88" . "88  
//                           (| -_- |)  
//                            O\ = /O  
//                        ____/`---'\____  
//                      .   ' \\| |// `.  
//                       / \\||| : |||// \  
//                     / _||||| -:- |||||- \  
//                       | | \\\ - /// | |  
//                     | \_| ''\---/'' | |  
//                      \ .-\__ `-` ___/-. /  
//                   ___`. .' /--.--\ `. . __  
//                ."" '< `.___\_<|>_/___.' >'"".  
//               | | : `- \`.;`\ _ /`;.`/ - ` : | |  
//                 \ \ `-. \_ __\ /__ _/ .-` / /  
//         ======`-.____`-.___\_____/___.-`____.-'======  
//                            `=---='  
//  
//         .............................................  
//                  佛祖镇楼                  BUG辟易  
//          佛曰:  
//                  写字楼里写字间，写字间里程序员；  
//                  程序人员写程序，又拿程序换酒钱。  
//                  酒醒只在网上坐，酒醉还来网下眠；  
//                  酒醉酒醒日复日，网上网下年复年。  
//                  但愿老死电脑间，不愿鞠躬老板前；  
//                  奔驰宝马贵者趣，公交自行程序员。  
//                  别人笑我忒疯癫，我笑自己命太贱；  
//  


import com.qianfeng.smartplatform.dto.EchartsHumDto;
import com.qianfeng.smartplatform.dto.R;
import com.qianfeng.smartplatform.pojo.Humiture;
import com.qianfeng.smartplatform.service.HumitureService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.*;

/**
 * Created by jackiechan on 2021-05-09/16:13
 *
 * @author jackiechan
 */
@RestController
@Api(tags = "温湿度报表模块" )
@RequestMapping("/humitures")
public class HumitureController {
    @Autowired
    private HumitureService humitureService;
    @GetMapping("/humitures")
    @ApiOperation("查询温湿度报表")
    public R getHumituresByParamMap(@ApiParam(name = "deviceUUID",value = "查询设备UUID",defaultValue = "1") @RequestParam(required = false) String deviceUUID,@RequestParam(required = false) String startdate,@RequestParam(required = false) String endstate) {
        Map<String, Object> paramMap = new HashMap<>();
        paramMap.put("deviceUUID", deviceUUID);
        paramMap.put("startdate", startdate);
        paramMap.put("endstate", endstate);
        List<Humiture> humitureList = humitureService.getHumituresByParamMap(paramMap);
        //图表需要的数据需要放在一起,所以在此进行转换
        List<Date> times = new ArrayList<>();
        List<Double> humidityList = new ArrayList<>();
        List<Double> temperatureList = new ArrayList<>();
        humitureList.forEach(
                humiture -> {
                    times.add(humiture.getUploadTime());
                    humidityList.add(humiture.getHumidity());
                    temperatureList.add(humiture.getTemperature());
                }
        );
//        Map<String, Object> resultMap = new HashMap<>(); //真正返回的数据map
//        resultMap.put("times", times);//保存时间
//        resultMap.put("humidityList", humidityList);//保存湿度
//        resultMap.put("temperatureList", temperatureList);//保存温度
        EchartsHumDto echartsHumDto = new EchartsHumDto();
        echartsHumDto.setHumidityList(humidityList);
        echartsHumDto.setTimes(times);
        echartsHumDto.setTemperatureList(temperatureList);
        return R.setOK(echartsHumDto);
    }
}
